diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-08-04 13:25:04 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-08-04 13:25:04 -0700 |
commit | bab54e3e567a7a895c6e3afaf9494660cb41b827 (patch) | |
tree | 5a565d14b0916bb212d3726fe3a01cef7be3fe86 /netdissect.c | |
parent | 91e08f888d86fc7bc83732ee216c4ea609691d1c (diff) | |
download | tcpdump-bab54e3e567a7a895c6e3afaf9494660cb41b827.tar.gz |
Add netdissect.c.
Diffstat (limited to 'netdissect.c')
-rw-r--r-- | netdissect.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/netdissect.c b/netdissect.c new file mode 100644 index 00000000..80b6e94d --- /dev/null +++ b/netdissect.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 1988-1997 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 1998-2012 Michael Richardson <mcr@tcpdump.org> + * The TCPDUMP project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <netdissect-stdinc.h> + +#include "netdissect.h" + +#ifdef USE_LIBSMI +#include <smi.h> +#endif + +/* + * Initialize anything that must be initialized before dissecting + * packets. + * + * This should be called at the beginning of the program; it does + * not need to be called, and should not be called, for every + * netdissect_options structure. + */ +int +nd_init(char *errbuf, size_t errbuf_size) +{ +#ifdef _WIN32 + WORD wVersionRequested; + WSADATA wsaData; + + /* + * Request Winsock 2.2; we expect Winsock 2. + */ + wVersionRequested = MAKEWORD(2, 2); + err = WSAStartup(wVersionRequested, &wsaData); + if (err != 0) { + strlcpy(errbuf, "Attempting to initialize Winsock failed", + errbuf_size); + return (-1); + } +#endif /* _WIN32 */ + +#ifdef USE_LIBSMI + /* + * XXX - should we just fail if this fails? Some of the + * libsmi calls may fail. + */ + smiInit("tcpdump"); +#endif + + /* + * Clears the error buffer, and uses it so we don't get + * "unused argument" warnings at compile time. + */ + snprintf(errbuf, errbuf_size, ""); + return (0); +} + +/* + * Clean up anything that ndo_init() did. + */ +void +nd_cleanup(void) +{ +#ifdef USE_LIBSMI + /* + * This appears, in libsmi 0.4.8, to do nothing if smiInit() + * wasn't done or failed, so we call it unconditionally. + */ + smiExit(); +#endif + +#ifdef _WIN32 + /* + * Undo the WSAStartup() call above. + */ + WSACleanup(); +#endif +} |