Commit c72b3ecf authored by Jondy Zhao's avatar Jondy Zhao

Use API to get/set ipv6 route later Windows Vista, otherwise ipv6 route

couldn't work in the Non-English platforms.
parent 2506b328
...@@ -19,7 +19,12 @@ ifneq "$(WINVER)" "" ...@@ -19,7 +19,12 @@ ifneq "$(WINVER)" ""
SRCS += cyginet.c SRCS += cyginet.c
OBJS += cyginet.o OBJS += cyginet.o
LDLIBS += -liphlpapi -lws2_32 -lwlanapi -lole32 -lsetupapi LDLIBS += -liphlpapi -lws2_32 -lwlanapi -lole32 -lsetupapi
ifeq "$(WINVER)" "XP"
CFLAGS += -D_WIN32_WINNT=0x0503 CFLAGS += -D_WIN32_WINNT=0x0503
else
CFLAGS += -D_WIN32_WINNT=0x0600
endif
endif endif
......
...@@ -31,12 +31,14 @@ Later Windows Vista, ...@@ -31,12 +31,14 @@ Later Windows Vista,
$ WINVER=VISTA make $ WINVER=VISTA make
WINVER could be XP, VISTA, WIN7, WIN8.
It will generate babeld.exe in the current directory. It will generate babeld.exe in the current directory.
Build testc.exe, it's used to verify the functions in the cyginet.c Build test.exe, it's used to verify the functions in the cyginet.c
$ WINVER=XP make testc.exe $ WINVER=XP make test.exe
$ ./testc.exe $ ./test.exe
Interface Names Interface Names
=============== ===============
......
...@@ -953,13 +953,13 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -953,13 +953,13 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
char sgate[INET6_ADDRSTRLEN]; char sgate[INET6_ADDRSTRLEN];
if (NULL == inet_ntop(AF_INET6, if (NULL == inet_ntop(AF_INET6,
(const void*)(&(((SOCKADDR_IN6*)dest)->sin6_addr)), (PVOID)(&(((SOCKADDR_IN6*)dest)->sin6_addr)),
sdest, sdest,
INET6_ADDRSTRLEN INET6_ADDRSTRLEN
)) ))
return -1; return -1;
if (NULL == inet_ntop(AF_INET6, if (NULL == inet_ntop(AF_INET6,
(const void*)(&(((SOCKADDR_IN6*)gate)->sin6_addr)), (PVOID)(&(((SOCKADDR_IN6*)gate)->sin6_addr)),
sgate, sgate,
INET6_ADDRSTRLEN INET6_ADDRSTRLEN
)) ))
...@@ -1086,13 +1086,14 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -1086,13 +1086,14 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
#endif /* if 0 */ #endif /* if 0 */
#else #else
do {
/* Add route entry after Windows Vista */ /* Add route entry after Windows Vista */
MIB_IPFORWARDROW2 Row2; MIB_IPFORWARD_ROW2 Row2;
unsigned long Res; unsigned long Res;
memset(&Row2, 0, sizeof(MIB_IPFORWARDROW2)); memset(&Row2, 0, sizeof(MIB_IPFORWARD_ROW2));
Row2.InterfaceLuid = NULL; /* Row2.InterfaceLuid = 0; */
/* Maybe in the Vista, both of indexs are same. */ /* Maybe in the Vista, both of indexs are same. */
Row2.InterfaceIndex = dest->sa_family == AF_INET6 ? Row2.InterfaceIndex = dest->sa_family == AF_INET6 ?
ifindex : libwinet_map_ifindex(AF_INET6, ifindex); ifindex : libwinet_map_ifindex(AF_INET6, ifindex);
...@@ -1106,7 +1107,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -1106,7 +1107,7 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
Row2.Protocol = MIB_IPPROTO_NETMGMT; Row2.Protocol = MIB_IPPROTO_NETMGMT;
Row2.Loopback = gate->sa_family == AF_INET6 ? Row2.Loopback = gate->sa_family == AF_INET6 ?
IN6_IS_ADDR_LOOPBACK(&(((SOCKADDR_IN6*)gate)->sin6_addr)) : IN6_IS_ADDR_LOOPBACK(&(((SOCKADDR_IN6*)gate)->sin6_addr)) :
IN_LOOPBACK(ntohl(((SOCKADDR_IN*)gate)->sin_addr.S_un.S_addr)); IN_LOOPBACK(ntohl((u_long)((SOCKADDR_IN*)gate)->sin_addr.S_un.S_addr));
Row2.AutoconfigureAddress = FALSE; Row2.AutoconfigureAddress = FALSE;
Row2.Publish = FALSE; Row2.Publish = FALSE;
Row2.Immortal = 0; Row2.Immortal = 0;
...@@ -1115,19 +1116,19 @@ libwinet_edit_route_entry(const struct sockaddr *dest, ...@@ -1115,19 +1116,19 @@ libwinet_edit_route_entry(const struct sockaddr *dest,
switch(cmdflag) { switch(cmdflag) {
case 0: case 0:
Res = CreateIpForwardEntry2(&Row); Res = CreateIpForwardEntry2(&Row2);
break; break;
case 1: case 1:
Res = SetIpForwardEntry2(&Row); Res = SetIpForwardEntry2(&Row2);
break; break;
case 2: case 2:
Res = DeleteIpForwardEntry2(&Row); Res = DeleteIpForwardEntry2(&Row2);
break; break;
} }
if (Res != NO_ERROR) if (Res != NO_ERROR)
return -1; return -1;
} } while (0);
#endif /* _WIN32_WINNT < _WIN32_WINNT_VISTA */ #endif /* _WIN32_WINNT < _WIN32_WINNT_VISTA */
...@@ -1671,18 +1672,18 @@ cyginet_dump_route_table(struct cyginet_route *routes, int maxroutes) ...@@ -1671,18 +1672,18 @@ cyginet_dump_route_table(struct cyginet_route *routes, int maxroutes)
PMIB_IPFORWARD_ROW2 pRow2; PMIB_IPFORWARD_ROW2 pRow2;
/* From Windows Vista later, use GetIpForwardTable2 instead */ /* From Windows Vista later, use GetIpForwardTable2 instead */
if (NO_ERROR == GetIpForwardTable2(family, if (NO_ERROR == GetIpForwardTable2(AF_UNSPEC,
pIpForwardTable2 &pIpForwardTable2
0)) { )) {
NumEntries = pIpForwardTable2->dwNumEntries; NumEntries = pIpForwardTable2->NumEntries;
if ((routes == NULL) || (NumEntries > maxroutes)) { if ((routes == NULL) || (NumEntries > maxroutes)) {
FreeMibTable(pIpForwardTable2); FreeMibTable(pIpForwardTable2);
return NumEntries; return NumEntries;
} }
proute = routes; proute = routes;
NumEntries = pIpForwardTable2->dwNumEntries; NumEntries = pIpForwardTable2->NumEntries;
pRow2 = pIpForwardTable2 -> Table; pRow2 = pIpForwardTable2 -> Table;
for (i = 0; i < NumEntries; i++, proute ++, pRow2 ++) { for (i = 0; i < NumEntries; i++, proute ++, pRow2 ++) {
...@@ -1690,12 +1691,12 @@ cyginet_dump_route_table(struct cyginet_route *routes, int maxroutes) ...@@ -1690,12 +1691,12 @@ cyginet_dump_route_table(struct cyginet_route *routes, int maxroutes)
proute -> metric = pRow2 -> Metric; proute -> metric = pRow2 -> Metric;
proute -> proto = pRow2 -> Protocol; proute -> proto = pRow2 -> Protocol;
proute -> plen = (pRow2 -> DestinationPrefix).PrefixLength; proute -> plen = (pRow2 -> DestinationPrefix).PrefixLength;
memcpy(proute -> prefix, memcpy(&proute -> prefix,
(pRow2 -> DestinationPrefix).DestinationPrefix, &(pRow2 -> DestinationPrefix).Prefix,
sizeof(SOCKADDR_INET) sizeof(SOCKADDR_INET)
); );
memcpy(proute -> gateway, memcpy(&proute -> gateway,
pRow2 -> NextHop, &pRow2 -> NextHop,
sizeof(SOCKADDR_INET) sizeof(SOCKADDR_INET)
); );
} }
...@@ -2616,6 +2617,8 @@ DWORD GetConnectedNetworks() ...@@ -2616,6 +2617,8 @@ DWORD GetConnectedNetworks()
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
#ifdef TEST_CYGINET #ifdef TEST_CYGINET
#define MAX_ROUTES 200
VOID PrintAllInterfaces() VOID PrintAllInterfaces()
{ {
IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL; IP_ADAPTER_ADDRESSES *pAdaptAddr = NULL;
...@@ -2895,7 +2898,6 @@ runTestCases() ...@@ -2895,7 +2898,6 @@ runTestCases()
printf("\n\nTest cyginet_dump_route_table:\n\n"); printf("\n\nTest cyginet_dump_route_table:\n\n");
do { do {
#define MAX_ROUTES 120
struct cyginet_route routes[MAX_ROUTES]; struct cyginet_route routes[MAX_ROUTES];
memset(routes, 0, sizeof(struct cyginet_route) * MAX_ROUTES); memset(routes, 0, sizeof(struct cyginet_route) * MAX_ROUTES);
int n = cyginet_dump_route_table(routes, MAX_ROUTES); int n = cyginet_dump_route_table(routes, MAX_ROUTES);
...@@ -2968,7 +2970,6 @@ runTestCases() ...@@ -2968,7 +2970,6 @@ runTestCases()
printf("\n\nTest cyginet_dump_route_table:\n\n"); printf("\n\nTest cyginet_dump_route_table:\n\n");
do { do {
#define MAX_ROUTES 120
struct cyginet_route routes[MAX_ROUTES]; struct cyginet_route routes[MAX_ROUTES];
memset(routes, 0, sizeof(struct cyginet_route) * MAX_ROUTES); memset(routes, 0, sizeof(struct cyginet_route) * MAX_ROUTES);
int n = cyginet_dump_route_table(routes, MAX_ROUTES); int n = cyginet_dump_route_table(routes, MAX_ROUTES);
...@@ -3157,7 +3158,7 @@ int main(int argc, char* argv[]) ...@@ -3157,7 +3158,7 @@ int main(int argc, char* argv[])
} }
} while(0); } while(0);
// runTestCases(); runTestCases();
/* printf("\n\nTest libwinet_init_ipv6_interface:\n\n"); */ /* printf("\n\nTest libwinet_init_ipv6_interface:\n\n"); */
/* libwinet_init_ipv6_interface(); */ /* libwinet_init_ipv6_interface(); */
......
...@@ -172,12 +172,17 @@ typedef struct _LIBWINET_INTERFACE { ...@@ -172,12 +172,17 @@ typedef struct _LIBWINET_INTERFACE {
SOCKADDR Address; SOCKADDR Address;
} LIBWINET_INTERFACE, *PLIBWINET_INTERFACE; } LIBWINET_INTERFACE, *PLIBWINET_INTERFACE;
#if _WIN32_WINNT < _WIN32_WINNT_VISTA
extern unsigned if_nametoindex (const char *); extern unsigned if_nametoindex (const char *);
extern char *if_indextoname (unsigned, char *); extern char *if_indextoname (unsigned, char *);
extern struct if_nameindex *if_nameindex (void);
extern void if_freenameindex (struct if_nameindex *);
extern const char *inet_ntop (int, const void *, char *, socklen_t); extern const char *inet_ntop (int, const void *, char *, socklen_t);
extern int inet_pton (int, const char *, void *); extern int inet_pton (int, const char *, void *);
#else
WINSOCK_API_LINKAGE u_long WSAAPI ntohl(u_long netlong);
#endif
extern struct if_nameindex *if_nameindex (void);
extern void if_freenameindex (struct if_nameindex *);
extern int getifaddrs(struct ifaddrs **); extern int getifaddrs(struct ifaddrs **);
extern void freeifaddrs(struct ifaddrs *); extern void freeifaddrs(struct ifaddrs *);
......
...@@ -285,7 +285,8 @@ mv slapos.tar.gz slapos/ ...@@ -285,7 +285,8 @@ mv slapos.tar.gz slapos/
Then build babeld and openvpn for cygwin, we need use the sources in the slapos.package.git, they are patched for cygwin: Then build babeld and openvpn for cygwin, we need use the sources in the slapos.package.git, they are patched for cygwin:
<programlisting> <programlisting>
cd /opt/git/slapos.package/windows/babeld cd /opt/git/slapos.package/windows/babeld
make WINVER=XP # WINVER could be XP, VISTA, WIN7, WIN8
WINVER=XP make
cp babeld.exe /usr/bin cp babeld.exe /usr/bin
cd /opt/git/slapos.package/windows/openvpn cd /opt/git/slapos.package/windows/openvpn
...@@ -544,4 +545,3 @@ The following packages are requied by re6stnet ...@@ -544,4 +545,3 @@ The following packages are requied by re6stnet
--> -->
</appendix> </appendix>
</book> </book>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment