Changeset 0e94b979 in mainline for uspace/app/inetcfg/inetcfg.c
- Timestamp:
- 2012-03-08T21:12:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 291c792
- Parents:
- a88a6eac
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/inetcfg/inetcfg.c
ra88a6eac r0e94b979 40 40 #include <loc.h> 41 41 #include <stdio.h> 42 #include <stdlib.h> 42 43 #include <str_error.h> 43 44 #include <sys/types.h> … … 86 87 } 87 88 89 static int naddr_format(inet_naddr_t *naddr, char **bufp) 90 { 91 int rc; 92 93 rc = asprintf(bufp, "%d.%d.%d.%d/%d", naddr->ipv4 >> 24, 94 (naddr->ipv4 >> 16) & 0xff, (naddr->ipv4 >> 8) & 0xff, 95 naddr->ipv4 & 0xff, naddr->bits); 96 97 if (rc < 0) 98 return ENOMEM; 99 100 return EOK; 101 } 102 88 103 static int addr_create_static(int argc, char *argv[]) 89 104 { … … 129 144 printf(NAME ": Failed creating static address '%s' (%d)\n", 130 145 "v4s", rc); 131 return 1; 132 } 146 return EIO; 147 } 148 149 return EOK; 150 } 151 152 static int addr_list(void) 153 { 154 sysarg_t *addr_list; 155 inet_addr_info_t ainfo; 156 inet_link_info_t linfo; 157 158 size_t count; 159 size_t i; 160 int rc; 161 char *astr; 162 163 rc = inetcfg_get_addr_list(&addr_list, &count); 164 if (rc != EOK) { 165 printf(NAME ": Failed getting address list.\n"); 166 return rc; 167 } 168 169 for (i = 0; i < count; i++) { 170 rc = inetcfg_addr_get(addr_list[i], &ainfo); 171 if (rc != EOK) { 172 printf("Failed getting properties of address %zu.\n", 173 (size_t)addr_list[i]); 174 continue; 175 } 176 177 rc = inetcfg_link_get(ainfo.ilink, &linfo); 178 if (rc != EOK) { 179 printf("Failed getting properties of link %zu.\n", 180 (size_t)ainfo.ilink); 181 continue; 182 } 183 184 rc = naddr_format(&ainfo.naddr, &astr); 185 if (rc != EOK) { 186 printf("Memory allocation failed.\n"); 187 goto out; 188 } 189 190 printf("%s %s %s\n", astr, linfo.name, 191 ainfo.name); 192 193 free(astr); 194 free(ainfo.name); 195 free(linfo.name); 196 } 197 out: 198 free(addr_list); 133 199 134 200 return EOK; … … 138 204 { 139 205 int rc; 140 141 if (argc < 2) {142 printf(NAME ": Missing argument.\n");143 print_syntax();144 return 1;145 }146 206 147 207 rc = inetcfg_init(); … … 150 210 rc); 151 211 return 1; 212 } 213 214 if (argc < 2) { 215 rc = addr_list(); 216 if (rc != EOK) 217 return 1; 218 return 0; 152 219 } 153 220
Note:
See TracChangeset
for help on using the changeset viewer.