• (OK) ip-str.c


    #include <stdio.h> 
    #include <string.h>
    
    #include <sys/types.h>  
    #include <sys/socket.h>  
    #include <arpa/inet.h> 
    
    int main(void)
    { 
      char *token;
      char buf1[16];
      char buf2[4][4];
      char buf3[16];
      int i = 0;
      struct sockaddr_in addr;
      memset(buf1, 0, 16);
      memset(buf2, 0, 16);
      memset(buf3, 0, 16);
    
      //buf = inet_ntoa(sin_dest.sin_addr);
      //sprintf(buf1, "%s", inet_ntoa(sin_dest.sin_addr));
    
      sprintf(buf1, "%s", "112.26.0.8");
    
      token = strtok(buf1, ".");
      while (token != NULL)
      {
        sprintf(buf2[i++], "%s", token);
        token = strtok(NULL, ".");
      }
    
      strcat(strcat(strcat(strcat(strcat(strcat(strcat(buf3,buf2[0]), "."), buf2[1]), "."), buf2[2]), "."), buf2[3]);
      inet_aton(buf3, &addr.sin_addr);
      printf("%s (%u)
    ", inet_ntoa(addr.sin_addr), addr.sin_addr.s_addr);
    
      buf2[2][0] = '1';
      memset(buf3, 0, 16);
      strcat(strcat(strcat(strcat(strcat(strcat(strcat(buf3,buf2[0]), "."), buf2[1]), "."), buf2[2]), "."), buf2[3]);
      inet_aton(buf3, &addr.sin_addr);
      printf("%s (%u)
    ", inet_ntoa(addr.sin_addr), addr.sin_addr.s_addr);
    
      buf2[2][0] = '2';
      memset(buf3, 0, 16);
      strcat(strcat(strcat(strcat(strcat(strcat(strcat(buf3,buf2[0]), "."), buf2[1]), "."), buf2[2]), "."), buf2[3]);
      inet_aton(buf3, &addr.sin_addr);
      printf("%s (%u)
    ", inet_ntoa(addr.sin_addr), addr.sin_addr.s_addr);
    
      buf2[2][0] = '3';
      memset(buf3, 0, 16);
      strcat(strcat(strcat(strcat(strcat(strcat(strcat(buf3,buf2[0]), "."), buf2[1]), "."), buf2[2]), "."), buf2[3]);
      inet_aton(buf3, &addr.sin_addr);
      printf("%s (%u)
    ", inet_ntoa(addr.sin_addr), addr.sin_addr.s_addr);
    
      buf2[2][0] = '4';
      memset(buf3, 0, 16);
      strcat(strcat(strcat(strcat(strcat(strcat(strcat(buf3,buf2[0]), "."), buf2[1]), "."), buf2[2]), "."), buf2[3]);
      inet_aton(buf3, &addr.sin_addr);
      printf("%s (%u)
    ", inet_ntoa(addr.sin_addr), addr.sin_addr.s_addr);
    
      addr.sin_addr.s_addr = inet_addr("112.26.9.8");
      printf("%s (%u)
    ", inet_ntoa(addr.sin_addr), addr.sin_addr.s_addr);
    
      //---------------------------------------
      const char *address = "255.255.255.255";
    
      inet_aton(address, &addr.sin_addr);
      printf("%s (%u)
    ", address, addr.sin_addr.s_addr);
      //---------------------------------------
    
      return 0;
    }
    


  • 相关阅读:
    iOS
    WKWebview 获取网页加载内容的高度
    iPhoneXS、XS Max与iPhoneXR 适配
    iOS:iPhone X,iPhone XS,iPhone XR,iPHone XS Max 适配
    git---全局设置用户名、密码、邮箱
    iOS 拖动手势(UIPanGestureRecognizer)
    ios 扩大button的点击区域
    iOS总结 | 修改button响应区域的各种姿势
    swift常用第三方库
    《从零开始学Swift》学习笔记(Day 33)——属性观察者
  • 原文地址:https://www.cnblogs.com/ztguang/p/12644655.html
Copyright © 2020-2023  润新知