(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/netmon.c) |
| |
| 788 | | | static gboolean netmon_dump_close(wtap_dumper *wdh, int *err) |
| 789 | | | { |
| 790 | | | netmon_dump_t *netmon = wdh->dump.netmon; |
| 791 | | | size_t n_to_write; |
| 792 | | | size_t nwritten; |
| 793 | | | struct netmon_hdr file_hdr; |
| 794 | | | const char *magicp; |
| 795 | | | size_t magic_size; |
| 796 | | | struct tm *tm; |
| 797 | | | |
| 798 | | | |
| 799 | | | |
| 800 | | | n_to_write = netmon->frame_table_index * sizeof *netmon->frame_table; |
| 801 | | | nwritten = fwrite(netmon->frame_table, 1, n_to_write, wdh->fh); |
| 802 | | | if (nwritten != n_to_write) { |
| 803 | | | if (err != NULL) { |
| 804 | | | if (nwritten == 0 && ferror(wdh->fh)) |
| 805 | | | *err = errno; |
| 806 | | | else |
| 807 | | | *err = WTAP_ERR_SHORT_WRITE; |
| 808 | | | } |
| 809 | | | return FALSE; |
| 810 | | | } |
| 811 | | | |
| 812 | | | |
| 813 | | | fseek(wdh->fh, 0, SEEK_SET);
x /usr/include/stdio.h |
| |
141 | #define SEEK_SET 0 /* Seek from beginning of file. */ |
| |
|
| 814 | | | memset(&file_hdr, '\0', sizeof file_hdr); |
| 815 | | | switch (wdh->file_type) { |
| 816 | | | |
| 817 | | | case WTAP_FILE_NETMON_1_x: |
| 818 | | | magicp = netmon_1_x_magic; |
| 819 | | | magic_size = sizeof netmon_1_x_magic; |
| 820 | | | |
| 821 | | | file_hdr.ver_major = 1; |
| 822 | | | file_hdr.ver_minor = 1; |
| 823 | | | break; |
| 824 | | | |
| 825 | | | case WTAP_FILE_NETMON_2_x: |
| 826 | | | magicp = netmon_2_x_magic; |
| 827 | | | magic_size = sizeof netmon_2_x_magic; |
| 828 | | | |
| 829 | | | |
| 830 | | | |
| 831 | | | |
| 832 | | | file_hdr.ver_major = 2; |
| 833 | | | file_hdr.ver_minor = 0; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 834 | | | break; |
| 835 | | | |
| 836 | | | default: |
| 837 | | | |
| 838 | | | |
| 839 | | | if (err != NULL) |
| 840 | | | *err = WTAP_ERR_UNSUPPORTED_FILE_TYPE; |
| 841 | | | return FALSE; |
| 842 | | | } |
| 843 | | | nwritten = fwrite(magicp, 1, magic_size, wdh->fh); |
| 844 | | | if (nwritten != magic_size) { |
| 845 | | | if (err != NULL) { |
| 846 | | | if (nwritten == 0 && ferror(wdh->fh)) |
| 847 | | | *err = errno; |
| 848 | | | else |
| 849 | | | *err = WTAP_ERR_SHORT_WRITE; |
| 850 | | | } |
| 851 | | | return FALSE; |
| 852 | | | } |
| 853 | | | |
| 854 | | | file_hdr.network = htoles(wtap_encap[wdh->encap]); |
| 855 | | | tm = localtime(&netmon->first_record_time.secs); |
| 856 | | | if (tm != NULL) { |
| 857 | | | file_hdr.ts_year = htoles(1900 + tm->tm_year); |
| 858 | | | file_hdr.ts_month = htoles(tm->tm_mon + 1); |
| 859 | | | file_hdr.ts_dow = htoles(tm->tm_wday); |
| 860 | | | file_hdr.ts_day = htoles(tm->tm_mday); |
| 861 | | | file_hdr.ts_hour = htoles(tm->tm_hour); |
| 862 | | | file_hdr.ts_min = htoles(tm->tm_min); |
| 863 | | | file_hdr.ts_sec = htoles(tm->tm_sec); |
| 864 | | | } else { |
| 865 | | | file_hdr.ts_year = htoles(1900 + 0); |
| 866 | | | file_hdr.ts_month = htoles(0 + 1); |
| 867 | | | file_hdr.ts_dow = htoles(0); |
| 868 | | | file_hdr.ts_day = htoles(0); |
| 869 | | | file_hdr.ts_hour = htoles(0); |
| 870 | | | file_hdr.ts_min = htoles(0); |
| 871 | | | file_hdr.ts_sec = htoles(0); |
| 872 | | | } |
| 873 | | | file_hdr.ts_msec = htoles(netmon->first_record_time.nsecs/1000000); |
| 874 | | | |
| 875 | | | file_hdr.frametableoffset = htolel(netmon->frame_table_offset); |
| 876 | | | file_hdr.frametablelength = |
| 877 | | | htolel(netmon->frame_table_index * sizeof *netmon->frame_table); |
| 878 | | | nwritten = fwrite(&file_hdr, 1, sizeof file_hdr, wdh->fh); |
| 879 | | | if (nwritten != sizeof file_hdr) { |
| 880 | | | if (err != NULL) { |
| 881 | | | if (nwritten == 0 && ferror(wdh->fh)) |
| 882 | | | *err = errno; |
| 883 | | | else |
| 884 | | | *err = WTAP_ERR_SHORT_WRITE; |
| 885 | | | } |
| 886 | | | return FALSE; |
| 887 | | | } |
| 888 | | | |
| 889 | | | return TRUE; |
| 890 | | | } |
| |