Ipv6的封包傳輸 In Ubunto - Linux
By Sandy
at 2009-10-17T16:42
at 2009-10-17T16:42
Table of Contents
#include <errno.h>
#include <error.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
int
main (int argc, char *argv[])
{
int result = 0;
struct addrinfo *ai;
struct addrinfo hints;
memset (&hints, '\0', sizeof(hints));
hints.ai_flags = AI_ADDRCONFIG;
hints.ai_socktype = SOCK_STREAM;
int e = getaddrinfo (argv[1], "echo", &hints, &ai);
if(e != 0)
error (EXIT_FAILURE, 0, "getaddrinfo: %s", gai_strerror (e));
struct addrinfo *runp = ai;
while (runp !=NULL)
{
int sock = socket (runp->ai_family, runp->ai_socktype,
runp->ai_protocol);
if (sock != -1)
{
if(connect (sock, runp->ai_addr, runp->ai_addrlen) == 0)
{
char *line = NULL;
size_t len = 0;
ssize_t n = getline (&line, &len, stdin);
write (sock, line, len);
n = read (sock, line ,len);
write (STDOUT_FILENO, line, n);
close (sock);
goto out;
}
close (sock);
}
runp = runp->ai_next;
}
error (0, 0, "cannot contact %s", argv[1]);
result = 1;
out:
freeaddrinfo (ai);
return result;
}
這是我參考
http://people.redhat.com/drepper/userapi-ipv6.html
寫的
目前我是使用ubuntu 9.多版
我用過直接帶入參數 0 進
不過找不到位置
--
#include <error.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
int
main (int argc, char *argv[])
{
int result = 0;
struct addrinfo *ai;
struct addrinfo hints;
memset (&hints, '\0', sizeof(hints));
hints.ai_flags = AI_ADDRCONFIG;
hints.ai_socktype = SOCK_STREAM;
int e = getaddrinfo (argv[1], "echo", &hints, &ai);
if(e != 0)
error (EXIT_FAILURE, 0, "getaddrinfo: %s", gai_strerror (e));
struct addrinfo *runp = ai;
while (runp !=NULL)
{
int sock = socket (runp->ai_family, runp->ai_socktype,
runp->ai_protocol);
if (sock != -1)
{
if(connect (sock, runp->ai_addr, runp->ai_addrlen) == 0)
{
char *line = NULL;
size_t len = 0;
ssize_t n = getline (&line, &len, stdin);
write (sock, line, len);
n = read (sock, line ,len);
write (STDOUT_FILENO, line, n);
close (sock);
goto out;
}
close (sock);
}
runp = runp->ai_next;
}
error (0, 0, "cannot contact %s", argv[1]);
result = 1;
out:
freeaddrinfo (ai);
return result;
}
這是我參考
http://people.redhat.com/drepper/userapi-ipv6.html
寫的
目前我是使用ubuntu 9.多版
我用過直接帶入參數 0 進
不過找不到位置
--
Tags:
Linux
All Comments
Related Posts
fedora 8 上如何安裝 virtualbox?
By Lucy
at 2009-10-17T13:51
at 2009-10-17T13:51
Linux ubuntu9.04 是否有內建看圖軟體?
By Eden
at 2009-10-17T02:21
at 2009-10-17T02:21
復製的用法
By Kelly
at 2009-10-17T01:01
at 2009-10-17T01:01
INIT:No inittab file found!
By Linda
at 2009-10-16T22:48
at 2009-10-16T22:48
fedora 8 上如何安裝 virtualbox?
By Yedda
at 2009-10-16T21:56
at 2009-10-16T21:56