Browse Source

renamed ip[46]_fmt to fmt_ip[46]

master
Felix von Leitner 19 years ago
parent
commit
76daeeab35
12 changed files with 85 additions and 72 deletions
  1. +8
    -2
      ip4.h
  2. +4
    -6
      ip6.h
  3. +27
    -0
      socket/fmt_ip4.3
  4. +3
    -3
      socket/fmt_ip4.c
  5. +32
    -0
      socket/fmt_ip6.3
  6. +1
    -1
      socket/fmt_ip6.c
  7. +1
    -1
      socket/fmt_ip6_flat.c
  8. +0
    -27
      socket/ip4_fmt.3
  9. +0
    -32
      socket/ip6_fmt.3
  10. +1
    -0
      socket/socket_connect6.c
  11. +1
    -0
      socket/socket_send6.c
  12. +7
    -0
      t.c

+ 8
- 2
ip4.h View File

@@ -1,9 +1,15 @@
#ifndef IP4_H
#define IP4_H

extern unsigned int ip4_scan(const char *src,char *ip);
extern unsigned int ip4_fmt(char *dest,const char *ip);
extern unsigned int scan_ip4(const char *src,char *ip);
extern unsigned int fmt_ip4(char *dest,const char *ip);

/* for djb backwards compatibility */
#define ip4_scan scan_ip4
#define ip4_fmt fmt_ip4

#define IP4_FMT 20

extern const char ip4loopback[4]; /* = {127,0,0,1};*/

#endif

+ 4
- 6
ip6.h View File

@@ -1,11 +1,11 @@
#ifndef IP6_H
#define IP6_H

extern unsigned int ip6_scan(const char *src,char *ip);
extern unsigned int ip6_fmt(char *dest,const char *ip);
extern unsigned int scan_ip6(const char *src,char *ip);
extern unsigned int fmt_ip6(char *dest,const char *ip);

extern unsigned int ip6_scan_flat(const char *src,char *);
extern unsigned int ip6_fmt_flat(char *dest,const char *);
extern unsigned int scan_ip6_flat(const char *src,char *);
extern unsigned int fmt_ip6_flat(char *dest,const char *);

/*
ip6 address syntax: (h = hex digit), no leading '0' required
@@ -23,6 +23,4 @@ extern const unsigned char V6any[16]; /*={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; */

#define ip6_isv4mapped(ip) (byte_equal(ip,12,V4mappedprefix))

extern const char ip4loopback[4]; /* = {127,0,0,1};*/

#endif

+ 27
- 0
socket/fmt_ip4.3 View File

@@ -0,0 +1,27 @@
.TH fmt_ip4 3
.SH NAME
fmt_ip4 \- write a formatted ASCII representation of an IPv4 number
.SH SYNTAX
.B #include <ip4.h>

unsigned int \fBfmt_ip4\fP(char *\fIdest\fR,const char \fIip\fR[4]);
.SH DESCRIPTION
fmt_ip4 formats an IPv4 number in dotted-decimal ASCII representation
from \fIip\fR and writes the result into \fIdest\fR. It returns the
number of bytes written.

If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_ip4 returns the number
of bytes it would have written.

fmt_ip4 does not append \\0.

For convenience, ip4.h defines the integer IP4_FMT to be big enough to
contain every possible fmt_ip4 output plus \\0.
.SH EXAMPLE
#include <ip4.h>

char buf[IP4_FMT];
char ip[4];
buf[fmt_ip4(buf,ip)]=0;
.SH "SEE ALSO"
scan_ip4(3), ip6_fmt(3)

socket/ip4_fmt.c → socket/fmt_ip4.c View File

@@ -1,7 +1,7 @@
#include "fmt.h"
#include "ip4.h"

unsigned int ip4_fmt(char *s,const char ip[4])
unsigned int fmt_ip4(char *s,const char ip[4])
{
unsigned int len;
int i;
@@ -10,7 +10,7 @@ unsigned int ip4_fmt(char *s,const char ip[4])
for (i=0; i<4; ++i) {
register unsigned int j;
len+=(j=fmt_ulong(s,(unsigned long) (unsigned char) ip[i]))+1;
if (s && i<3) { s+=i; *s++='.'; }
if (s && i<3) { s+=j; *s++='.'; }
}
return len;
return len-1;
}

+ 32
- 0
socket/fmt_ip6.3 View File

@@ -0,0 +1,32 @@
.TH fmt_ip6 3
.SH NAME
fmt_ip6 \- write a formatted ASCII representation of an IPv6 number
.SH SYNTAX
.B #include <ip6.h>

unsigned int \fBfmt_ip6\fP(char *\fIdest\fR,const char \fIip\fR[16]);
.SH DESCRIPTION
fmt_ip6 formats an IPv6 number in ASCII representation from \fIip\fR and
writes the result into \fIdest\fR. It returns the number of bytes
written.

fmt_ip6 will apply "::" compression to the output.

If \fIip\fR is an IPv4-mapped IPv6 address, fmt_ip6 will output the last
4 bytes as IPv4 number in dotted-decimal notation.

If \fIdest\fR equals FMT_LEN (i.e. is zero), fmt_ip6 returns the number
of bytes it would have written.

fmt_ip6 does not append \\0.

For convenience, ip6.h defines the integer IP6_FMT to be big enough to
contain every possible fmt_ip6 output plus \\0.
.SH EXAMPLE
#include <ip6.h>

char buf[IP6_FMT];
char ip[16];
buf[fmt_ip6(buf,ip)]=0;
.SH "SEE ALSO"
scan_ip6(3), ip4_fmt(3)

socket/ip6_fmt.c → socket/fmt_ip6.c View File

@@ -3,7 +3,7 @@
#include "ip4.h"
#include "ip6.h"

unsigned int ip6_fmt(char *s,const char ip[16])
unsigned int fmt_ip6(char *s,const char ip[16])
{
unsigned int len;
unsigned int i;

socket/ip6_fmt_flat.c → socket/fmt_ip6_flat.c View File

@@ -9,7 +9,7 @@ static char tohex(char num) {
return -1;
}

unsigned int ip6_fmt_flat(char *s,const char ip[16])
unsigned int fmt_ip6_flat(char *s,const char ip[16])
{
int i;
if (!s) return 32;

+ 0
- 27
socket/ip4_fmt.3 View File

@@ -1,27 +0,0 @@
.TH ip4_fmt 3
.SH NAME
ip4_fmt \- write a formatted ASCII representation of an IPv4 number
.SH SYNTAX
.B #include <ip4.h>

unsigned int \fBip4_fmt\fP(char *\fIdest\fR,const char \fIip\fR[4]);
.SH DESCRIPTION
ip4_fmt formats an IPv4 number in dotted-decimal ASCII representation
from \fIip\fR and writes the result into \fIdest\fR. It returns the
number of bytes written.

If \fIdest\fR equals FMT_LEN (i.e. is zero), ip4_fmt returns the number
of bytes it would have written.

ip4_fmt does not append \\0.

For convenience, ip4.h defines the integer IP4_FMT to be big enough to
contain every possible ip4_fmt output plus \\0.
.SH EXAMPLE
#include <ip4.h>

char buf[IP4_FMT];
char ip[4];
buf[ip4_fmt(buf,ip)]=0;
.SH "SEE ALSO"
ip4_scan(3), ip6_fmt(3)

+ 0
- 32
socket/ip6_fmt.3 View File

@@ -1,32 +0,0 @@
.TH ip6_fmt 3
.SH NAME
ip6_fmt \- write a formatted ASCII representation of an IPv6 number
.SH SYNTAX
.B #include <ip6.h>

unsigned int \fBip6_fmt\fP(char *\fIdest\fR,const char \fIip\fR[16]);
.SH DESCRIPTION
ip6_fmt formats an IPv6 number in ASCII representation from \fIip\fR and
writes the result into \fIdest\fR. It returns the number of bytes
written.

ip6_fmt will apply "::" compression to the output.

If \fIip\fR is an IPv4-mapped IPv6 address, ip6_fmt will output the last
4 bytes as IPv4 number in dotted-decimal notation.

If \fIdest\fR equals FMT_LEN (i.e. is zero), ip6_fmt returns the number
of bytes it would have written.

ip6_fmt does not append \\0.

For convenience, ip6.h defines the integer IP6_FMT to be big enough to
contain every possible ip6_fmt output plus \\0.
.SH EXAMPLE
#include <ip6.h>

char buf[IP6_FMT];
char ip[16];
buf[ip6_fmt(buf,ip)]=0;
.SH "SEE ALSO"
ip6_scan(3), ip4_fmt(3)

+ 1
- 0
socket/socket_connect6.c View File

@@ -9,6 +9,7 @@
#include "haveip6.h"
#include "error.h"
#include "uint32.h"
#include "ip4.h"

int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
{


+ 1
- 0
socket/socket_send6.c View File

@@ -7,6 +7,7 @@
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "ip4.h"

int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
{


+ 7
- 0
t.c View File

@@ -6,13 +6,20 @@
#include "stralloc.h"
#include "socket.h"
#include "buffer.h"
#include "ip4.h"

#define rdtscl(low) \
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")

int main(int argc,char* argv[]) {
char buf[100];
buf[ip4_fmt(buf,ip4loopback)]=0;
buffer_puts(buffer_1small,buf);
buffer_flush(buffer_1small);
#if 0
buffer_puts(buffer_1small,"hello, world\n");
buffer_flush(buffer_1small);
#endif
#if 0
int s=socket_tcp4();
char ip[4]={127,0,0,1};


Loading…
Cancel
Save