[問題]Ipv6的封包傳輸 In Ubunto
#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 進
不過找不到位置
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.87.164
Linux 近期熱門文章
21
56
PTT數位生活區 即時熱門文章