1 /* $Id: getconnstatus.c,v 1.6 2013/03/23 10:46:54 nanard Exp $ */
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2011-2013 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
10 #include <netinet/in.h>
11 #include "getconnstatus.h"
12 #include "getifaddr.h"
14 #define STATUS_UNCONFIGURED (0)
15 #define STATUS_CONNECTING (1)
16 #define STATUS_CONNECTED (2)
17 #define STATUS_PENDINGDISCONNECT (3)
18 #define STATUS_DISCONNECTING (4)
19 #define STATUS_DISCONNECTED (5)
22 * get the connection status
27 * 3 - PendingDisconnect
31 get_wan_connection_status(const char * ifname
)
33 char addr
[INET_ADDRSTRLEN
];
36 /* we need a better implementation here.
37 * I'm afraid it should be device specific */
38 r
= getifaddr(ifname
, addr
, INET_ADDRSTRLEN
, NULL
, NULL
);
39 return (r
< 0) ? STATUS_DISCONNECTED
: STATUS_CONNECTED
;
43 * return the same value as get_wan_connection_status()
46 get_wan_connection_status_str(const char * ifname
)
49 const char * str
= NULL
;
51 status
= get_wan_connection_status(ifname
);
63 str
= "PendingDisconnect";
66 str
= "Disconnecting";