blob: 543f08331dc5bdda7c0403bedf52dd4fca90dcad [file] [log] [blame]
Haibo Huangee759ce2021-01-05 21:34:29 -08001.\" Copyright (c) 1994, 1996, 1997
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that: (1) source code distributions
6.\" retain the above copyright notice and this paragraph in its entirety, (2)
7.\" distributions including binary code include the above copyright notice and
8.\" this paragraph in its entirety in the documentation or other materials
9.\" provided with the distribution, and (3) all advertising materials mentioning
10.\" features or use of this software display the following acknowledgement:
11.\" ``This product includes software developed by the University of California,
12.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13.\" the University nor the names of its contributors may be used to endorse
14.\" or promote products derived from this software without specific prior
15.\" written permission.
16.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19.\"
20.TH PCAP_INIT 3PCAP "11 April 2020"
21.SH NAME
22pcap_init \- initialize the library
23.SH SYNOPSIS
24.nf
25.ft B
26#include <pcap/pcap.h>
27.ft
28.LP
29.nf
30.ft B
31char errbuf[PCAP_ERRBUF_SIZE];
32.ft
33.LP
34.ft B
35int pcap_init(unsigned int opts, char *errbuf);
36.ft
37.fi
38.SH DESCRIPTION
39.BR pcap_init ()
40is used to initialize the Packet Capture library.
41.I opts
42specifies options for the library;
43currently, the options are:
44.TP
45.B PCAP_CHAR_ENC_LOCAL
46Treat all strings supplied as arguments, and return all strings to the
47caller, as being in the local character encoding.
48.TP
49.B PCAP_CHAR_ENC_UTF_8
50Treat all strings supplied as arguments, and return all strings to the
51caller, as being in UTF-8.
52.PP
53On UNIX-like systems, the local character encoding is assumed to be
54UTF-8, so no character encoding transformations are done.
55.PP
56On Windows, the local character encoding is the local ANSI code page.
57.PP
58If
59.BR pcap_init ()
60is not called, strings are treated as being in the local ANSI code page
61on Windows,
62.BR pcap_lookupdev (3PCAP)
63will succeed if there is a device on which to capture, and
64.BR pcap_create (3PCAP)
65makes an attempt to check whether the string passed as an argument is a
66UTF-16LE string - note that this attempt is unsafe, as it may run past
67the end of the string - to handle
68.BR pcap_lookupdev ()
69returning a UTF-16LE string. Programs that don't call
70.BR pcap_init ()
71should, on Windows, call
72.BR pcap_wsockinit ()
73to initialize Winsock; this is not necessary if
74.BR pcap_init ()
75is called, as
76.BR pcap_init ()
77will initialize Winsock itself on Windows.
78.SH RETURN VALUE
79.BR pcap_init ()
80returns
81.B 0
82on success and
83.B \-1
84on failure.
85If
86.B \-1
87is returned,
88.I errbuf
89is filled in with an appropriate error message.
90.I errbuf
91is assumed to be able to hold at least
92.B PCAP_ERRBUF_SIZE
93chars.
94.SH BACKWARD COMPATIBILITY
95This function became available in libpcap release 1.10.0. In previous
96releases, on Windows, all strings supplied as arguments, and all strings
97returned to the caller, are in the local character encoding.
98.SH SEE ALSO
99.BR pcap (3PCAP)