-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to the common framework for sockets
- Loading branch information
Showing
22 changed files
with
346 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "site_wright"] | ||
path = site_wright | ||
url = https://github.com/tehmaze-labs/wright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule site_wright
added at
7cb41c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef _COMMON_FORMAT_H | ||
#define _COMMON_FORMAT_H | ||
|
||
#include <stddef.h> | ||
#include "common/socket.h" | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
unsigned int format_ip4(char *dst, const ip4_t ip); | ||
unsigned int format_ip6(char *dst, const ip6_t ip); | ||
size_t format_ulong(char *dst, unsigned long i); | ||
size_t format_xlong(char *dst, unsigned long i); | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif // _COMMON_FORMAT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "common/format.h" | ||
#include "common/socket.h" | ||
|
||
unsigned int format_ip4(char *dst, const ip4_t ip) | ||
{ | ||
unsigned int len; | ||
int i; | ||
|
||
len = 0; | ||
for (i=0; i < 4; ++i) { | ||
register unsigned int j; | ||
len += (j = format_ulong(dst, (unsigned long)(unsigned char)ip[i])) + 1; | ||
if (dst && i < 3) { | ||
dst += j; | ||
*dst++ = '.'; | ||
} | ||
} | ||
return len - 1; | ||
} | ||
|
||
unsigned int format_ip6(char *dst, const ip6_t ip) | ||
{ | ||
unsigned long len, temp, k, pos0 = 0, len0 = 0, pos1 = 0, compr = 0; | ||
|
||
for (k = 0; k < 16; k += 2) { | ||
if (ip[k] == 0 && ip[k + 1] == 0) { | ||
if (!compr) { | ||
compr = 1; | ||
pos1 = k; | ||
} | ||
if (k == 14) { | ||
k = 16; | ||
goto last; | ||
} | ||
} else if (compr) { | ||
last: | ||
if ((temp = k - pos1) > len0) { | ||
len0 = temp; | ||
pos0 = pos1; | ||
} | ||
compr = 0; | ||
} | ||
} | ||
|
||
for (len = 0, k = 0; k < 16; k += 2) { | ||
if (k == 12 && isip4mapped(ip)) { | ||
len += format_ip4(dst, ip+12); | ||
break; | ||
} | ||
if (pos0 == k && len0) { | ||
if (k == 0) { | ||
++len; | ||
if (dst) { | ||
*dst++ = ':'; | ||
} | ||
} | ||
++len; | ||
if (dst) { | ||
*dst++ = ':'; | ||
} | ||
k += len0-2; | ||
continue; | ||
} | ||
temp = ((unsigned long) (unsigned char) ip[k] << 8) + | ||
(unsigned long) (unsigned char) ip[k + 1]; | ||
temp = format_xlong(dst, temp); | ||
len += temp; | ||
if (dst) { | ||
dst += temp; | ||
} | ||
if (k < 14) { | ||
++len; | ||
if (dst) { | ||
*dst++ = ':'; | ||
} | ||
} | ||
} | ||
return len; | ||
} |
Oops, something went wrong.