diff options
| author | Robert Pluim | 2019-11-15 11:11:30 +0100 |
|---|---|---|
| committer | Robert Pluim | 2019-11-26 08:46:13 +0100 |
| commit | 650a514e996287106f9a9525b6f27068ec2a0cbf (patch) | |
| tree | 188170aae76f32d894d8df1baa7f435fbfe99d88 /doc | |
| parent | 5c3d0cf7910afa6b3fbdba24ac5c5817f268eb0e (diff) | |
| download | emacs-650a514e996287106f9a9525b6f27068ec2a0cbf.tar.gz emacs-650a514e996287106f9a9525b6f27068ec2a0cbf.zip | |
Extend network-interface-list to return IPv6 and network info
Bug#38218
* src/process.c (Fnetwork_interface_list): Extend argument list to
allow requesting full network info and/or IPv4/IPv6 info.
(network_interface_list) [HAVE_GETIFADDRS]: Use getifaddrs to retrieve
interface IP addresses.
* src/process.h: Update prototype of network_interface_list.
* src/w32.c (g_b_init_get_adapters_addresses): New init flag.
(globals_of_w32): Initialize it.
(GetAdaptersAddresses_Proc): New function typedef.
(get_adapters_addresses): New wrapper function.
(init_winsock): Load htonl and ntohl.
(sys_htonl, sys_ntohl): New wrapper functions.
(network_interface_list): Implement in terms of
get_adapters_addresses.
* nt/inc/sys/socket.h: Add sys_htonl and sys_ntohl prototypes.
* etc/NEWS: Announce IPv4/IPv6 changes in network-interface-list.
* doc/lispref/processes.texi (Misc Network): Document updated arglist
and return values for network-interface-list.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/processes.texi | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index fc5832253f9..e33ae287ff9 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi | |||
| @@ -2971,12 +2971,67 @@ non-@code{nil} if that particular network option is supported by | |||
| 2971 | on network connections. Note that they are supported only on some | 2971 | on network connections. Note that they are supported only on some |
| 2972 | systems. | 2972 | systems. |
| 2973 | 2973 | ||
| 2974 | @defun network-interface-list | 2974 | @defun network-interface-list &optional full family |
| 2975 | This function returns a list describing the network interfaces | 2975 | This function returns a list describing the network interfaces of the |
| 2976 | of the machine you are using. The value is an alist whose | 2976 | machine you are using. The value is an alist whose elements have the |
| 2977 | elements have the form @code{(@var{name} . @var{address})}. | 2977 | form @code{(@var{ifname} . @var{address})}. @var{ifname} is a string |
| 2978 | @var{address} has the same form as the @var{local-address} | 2978 | naming the interface, @var{address} has the same form as the |
| 2979 | and @var{remote-address} arguments to @code{make-network-process}. | 2979 | @var{local-address} and @var{remote-address} arguments to |
| 2980 | @code{make-network-process}, i.e. a vector of integers. By default | ||
| 2981 | both IPv4 and IPv6 addresses are returned if possible. | ||
| 2982 | |||
| 2983 | Optional argument @var{full} non-@code{nil} means to instead return a | ||
| 2984 | list of one or more elements of the form @w{@code{(@var{ifname} | ||
| 2985 | @var{addr} @var{bcast} @var{netmask})}}. @var{ifname} is a non-unique | ||
| 2986 | string naming the interface. @var{addr}, @var{bcast}, and | ||
| 2987 | @var{netmask} are vectors of integers detailing the IP address, | ||
| 2988 | broadcast address, and network mask. | ||
| 2989 | |||
| 2990 | Optional argument @var{family} specified as symbol @code{ipv4} or | ||
| 2991 | @code{ipv6} restricts the returned information to IPv4 and IPv6 | ||
| 2992 | addresses respectively, independently of the value of @var{full}. | ||
| 2993 | Speficying @code{ipv6} when IPv6 support is not available will result | ||
| 2994 | in an error being signaled. | ||
| 2995 | |||
| 2996 | Some examples: | ||
| 2997 | |||
| 2998 | @example | ||
| 2999 | (network-interface-list) @result{} | ||
| 3000 | (("vmnet8" . | ||
| 3001 | [172 16 76 1 0]) | ||
| 3002 | ("vmnet1" . | ||
| 3003 | [172 16 206 1 0]) | ||
| 3004 | ("lo0" . | ||
| 3005 | [65152 0 0 0 0 0 0 1 0]) | ||
| 3006 | ("lo0" . | ||
| 3007 | [0 0 0 0 0 0 0 1 0]) | ||
| 3008 | ("lo0" . | ||
| 3009 | [127 0 0 1 0])) | ||
| 3010 | @end example | ||
| 3011 | |||
| 3012 | @example | ||
| 3013 | (network-interface-list t) @result{} | ||
| 3014 | (("vmnet8" | ||
| 3015 | [172 16 76 1 0] | ||
| 3016 | [172 16 76 255 0] | ||
| 3017 | [255 255 255 0 0]) | ||
| 3018 | ("vmnet1" | ||
| 3019 | [172 16 206 1 0] | ||
| 3020 | [172 16 206 255 0] | ||
| 3021 | [255 255 255 0 0]) | ||
| 3022 | ("lo0" | ||
| 3023 | [65152 0 0 0 0 0 0 1 0] | ||
| 3024 | [65152 0 0 0 65535 65535 65535 65535 0] | ||
| 3025 | [65535 65535 65535 65535 0 0 0 0 0]) | ||
| 3026 | ("lo0" | ||
| 3027 | [0 0 0 0 0 0 0 1 0] | ||
| 3028 | [0 0 0 0 0 0 0 1 0] | ||
| 3029 | [65535 65535 65535 65535 65535 65535 65535 65535 0]) | ||
| 3030 | ("lo0" | ||
| 3031 | [127 0 0 1 0] | ||
| 3032 | [127 255 255 255 0] | ||
| 3033 | [255 0 0 0 0])) | ||
| 3034 | @end example | ||
| 2980 | @end defun | 3035 | @end defun |
| 2981 | 3036 | ||
| 2982 | @defun network-interface-info ifname | 3037 | @defun network-interface-info ifname |
| @@ -2996,6 +3051,8 @@ The layer 2 address (Ethernet MAC address, for instance). | |||
| 2996 | @item flags | 3051 | @item flags |
| 2997 | The current flags of the interface. | 3052 | The current flags of the interface. |
| 2998 | @end table | 3053 | @end table |
| 3054 | |||
| 3055 | Note that this function returns only IPv4 information. | ||
| 2999 | @end defun | 3056 | @end defun |
| 3000 | 3057 | ||
| 3001 | @defun format-network-address address &optional omit-port | 3058 | @defun format-network-address address &optional omit-port |