Chinaunix首页 | 论坛 | 博客
  • 博客访问: 288516
  • 博文数量: 103
  • 博客积分: 2345
  • 博客等级: 大尉
  • 技术积分: 902
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-01 09:10
文章分类

全部博文(103)

文章存档

2022年(1)

2018年(3)

2017年(2)

2016年(3)

2015年(8)

2014年(8)

2013年(2)

2012年(9)

2011年(29)

2010年(20)

2009年(18)

我的朋友

分类:

2010-08-27 12:49:04

设置本地计算机ip地址

setip.c

#include 

#include 

#include 

#include 

#include   {

                                              / * Interface name */
           char                              ifr_name[IFNAMSIZ];

           union {
                   struct sockaddr    ifr_addr;
                   struct sockaddr    ifr_dstaddr;
                   struct sockaddr    ifr_broadaddr;
                   struct sockaddr    ifr_netmask;
                   struct sockaddr    ifr_hwaddr;
                   short                      ifr_flags;
                   int                           ifr_ifindex;
                   int                           ifr_metric;
                   int                           ifr_mtu;
                   struct ifmap              ifr_map;
                   char                        ifr_slave[IFNAMSIZ];
                   char                        ifr_newname[IFNAMSIZ];
                   char *                     ifr_data;
           };
       };

  {
        unsigned short sa_family;   //族, AF_xxx    AF_INET 不涉及转序的问题
        char sa_data[14];    // 14字节的地址 字节顺序的
    };
   
上面是通用的socket地址,共16个字节!

具体到Internet socket,用下面的结构,二者可以进行类型转换
struct sockaddr_in {
        short int sin_family; /* 地址族 */
        unsigned short int sin_port; /* 端口号 */
       struct in_addr sin_addr; /* Internet地址 */
        unsigned char sin_zero[8]; /* 与struct sockaddr一样的长度 */ 16个字节
    };

 
 

{

#include string.h

#include sys/socket.h

#include sys/ioctl.h

#include stdio.h

#include arpa/inet.h

#include netinet/in.h

#include net/if.h

        #include net/if_arp.h

      }

阅读(1484) | 评论(0) | 转发(0) |
0

上一篇:移植NET-SNMP

下一篇:在ARM Linux上移植Apache

给主人留下些什么吧!~~