Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ikeadm.c
          +++ new/usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ikeadm.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   *
  21   21   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  22   22   * Use is subject to license terms.
  23   23   */
  24   24  
  25      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  26      -
  27   25  #include <unistd.h>
  28   26  #include <stdio.h>
  29   27  #include <stdarg.h>
  30   28  #include <stdlib.h>
  31   29  #include <sys/sysconf.h>
  32   30  #include <string.h>
  33   31  #include <strings.h>
  34   32  #include <libintl.h>
  35   33  #include <locale.h>
  36   34  #include <ctype.h>
↓ open down ↓ 332 lines elided ↑ open up ↑
 369  367                  struct objtbl   objt[MAXOBJS];
 370  368          } table[] = {
 371  369                  {"get", IKE_SVC_ERROR, {
 372  370                                  {"debug",       IKE_SVC_GET_DBG},
 373  371                                  {"priv",        IKE_SVC_GET_PRIV},
 374  372                                  {"stats",       IKE_SVC_GET_STATS},
 375  373                                  {"p1",          IKE_SVC_GET_P1},
 376  374                                  {"rule",        IKE_SVC_GET_RULE},
 377  375                                  {"preshared",   IKE_SVC_GET_PS},
 378  376                                  {"defaults",    IKE_SVC_GET_DEFS},
 379      -                                {NULL,          IKE_SVC_ERROR},
      377 +                                {NULL,          IKE_SVC_ERROR}
 380  378                          }
 381  379                  },
 382  380                  {"set", IKE_SVC_ERROR, {
 383  381                                  {"debug",       IKE_SVC_SET_DBG},
 384  382                                  {"priv",        IKE_SVC_SET_PRIV},
 385      -                                {NULL,          IKE_SVC_ERROR},
      383 +                                {NULL,          IKE_SVC_ERROR}
 386  384                          }
 387  385                  },
 388  386                  {"add", IKE_SVC_ERROR, {
 389  387                                  {"rule",        IKE_SVC_NEW_RULE},
 390  388                                  {"preshared",   IKE_SVC_NEW_PS},
 391      -                                {NULL,          IKE_SVC_ERROR},
      389 +                                {NULL,          IKE_SVC_ERROR}
 392  390                          }
 393  391                  },
 394  392                  {"del", IKE_SVC_ERROR, {
 395  393                                  {"p1",          IKE_SVC_DEL_P1},
 396  394                                  {"rule",        IKE_SVC_DEL_RULE},
 397  395                                  {"preshared",   IKE_SVC_DEL_PS},
 398      -                                {NULL,          IKE_SVC_ERROR},
      396 +                                {NULL,          IKE_SVC_ERROR}
 399  397                          }
 400  398                  },
 401  399                  {"dump", IKE_SVC_ERROR, {
 402  400                                  {"p1",          IKE_SVC_DUMP_P1S},
 403  401                                  {"rule",        IKE_SVC_DUMP_RULES},
 404  402                                  {"preshared",   IKE_SVC_DUMP_PS},
 405      -                                {NULL,          IKE_SVC_ERROR},
      403 +                                {NULL,          IKE_SVC_ERROR}
 406  404                          }
 407  405                  },
 408  406                  {"flush", IKE_SVC_ERROR, {
 409  407                                  {"p1",          IKE_SVC_FLUSH_P1S},
 410      -                                {NULL,          IKE_SVC_ERROR},
      408 +                                {NULL,          IKE_SVC_ERROR}
 411  409                          }
 412  410                  },
 413  411                  {"read", IKE_SVC_ERROR, {
 414  412                                  {"rule",        IKE_SVC_READ_RULES},
 415  413                                  {"preshared",   IKE_SVC_READ_PS},
 416      -                                {NULL,          IKE_SVC_ERROR},
      414 +                                {NULL,          IKE_SVC_ERROR}
 417  415                          }
 418  416                  },
 419  417                  {"write", IKE_SVC_ERROR, {
 420  418                                  {"rule",        IKE_SVC_WRITE_RULES},
 421  419                                  {"preshared",   IKE_SVC_WRITE_PS},
 422      -                                {NULL,          IKE_SVC_ERROR},
      420 +                                {NULL,          IKE_SVC_ERROR}
 423  421                          }
 424  422                  },
 425  423                  {"help", IKEADM_HELP_GENERAL, {
 426  424                                  {"get",         IKEADM_HELP_GET},
 427  425                                  {"set",         IKEADM_HELP_SET},
 428  426                                  {"add",         IKEADM_HELP_ADD},
 429  427                                  {"del",         IKEADM_HELP_DEL},
 430  428                                  {"dump",        IKEADM_HELP_DUMP},
 431  429                                  {"flush",       IKEADM_HELP_FLUSH},
 432  430                                  {"read",        IKEADM_HELP_READ},
 433  431                                  {"write",       IKEADM_HELP_WRITE},
 434  432                                  {"help",        IKEADM_HELP_HELP},
 435      -                                {NULL,          IKE_SVC_ERROR},
      433 +                                {NULL,          IKE_SVC_ERROR}
 436  434                          }
 437  435                  },
 438  436                  {"exit", IKEADM_EXIT, {
 439      -                                {NULL,          IKE_SVC_ERROR},
      437 +                                {NULL,          IKE_SVC_ERROR}
 440  438                          }
 441  439                  },
 442  440                  {"quit", IKEADM_EXIT, {
 443      -                                {NULL,          IKE_SVC_ERROR},
      441 +                                {NULL,          IKE_SVC_ERROR}
 444  442                          }
 445  443                  },
 446  444                  {"dbg", IKE_SVC_ERROR, {
 447  445                                  {"rbdump",      IKE_SVC_DBG_RBDUMP},
 448      -                                {NULL,          IKE_SVC_ERROR},
      446 +                                {NULL,          IKE_SVC_ERROR}
 449  447                          }
 450  448                  },
 451  449                  {NULL,  IKE_SVC_ERROR, {
 452      -                                {NULL,          IKE_SVC_ERROR},
      450 +                                {NULL,          IKE_SVC_ERROR}
 453  451                          }
 454      -                },
      452 +                }
 455  453          };
 456  454          struct cmdtbl   *ct = table;
 457  455          struct objtbl   *ot;
 458  456  
 459  457          if (cmdstr == NULL) {
 460  458                  return (IKE_SVC_ERROR);
 461  459          }
 462  460  
 463  461          while (ct->cmd != NULL && strcmp(ct->cmd, cmdstr) != 0)
 464  462                  ct++;
↓ open down ↓ 666 lines elided ↑ open up ↑
1131 1129          if (keyp != NULL)
1132 1130                  free(keyp);
1133 1131          if (psp != NULL)
1134 1132                  free(psp);
1135 1133  
1136 1134          *presharedpp = NULL;
1137 1135  
1138 1136          return (-1);
1139 1137  }
1140 1138  
1141      -/* stolen from libdhcputil (dhcp_inittab.c) */
1142      -static uint64_t
1143      -ike_ntohll(uint64_t nll)
1144      -{
1145      -#ifdef  _LITTLE_ENDIAN
1146      -        return ((uint64_t)ntohl(nll & 0xffffffff) << 32 | ntohl(nll >> 32));
1147      -#else
1148      -        return (nll);
1149      -#endif
1150      -}
1151      -
1152 1139  /*
1153 1140   * Printing functions
1154 1141   *
1155 1142   * A potential point of confusion here is that the ikeadm-specific string-
1156 1143   * producing functions do not match the ipsec_util.c versions in style: the
1157 1144   * ikeadm-specific functions return a string (and are named foostr), while
1158 1145   * the ipsec_util.c functions actually print the string to the file named
1159 1146   * in the second arg to the function (and are named dump_foo).
1160 1147   *
1161      - * The reason for this is that in the context of the ikeadm output, it
1162      - * seemed like the localization of the text would be more straightforward
1163      - * (and could more easily accomodate non-english grammar!) if more complete
1164      - * phrases were being translated, rather than a bit of a phrase followed by
1165      - * a call to dump_foo() followed by more of the phrase.
     1148 + * Localization for ikeadm seems more straightforward when complete
     1149 + * phrases are translated rather than: a part of a phrase, a call to
     1150 + * dump_foo(), and more of the phrase.  It could also accommodate
     1151 + * non-English grammar more easily.
1166 1152   */
1167 1153  
1168 1154  static char *
1169 1155  errstr(int err)
1170 1156  {
1171 1157          static char     rtn[MAXLINESIZE];
1172 1158  
1173 1159          switch (err) {
1174 1160          case IKE_ERR_NO_OBJ:
1175 1161                  return (gettext("No data returned"));
↓ open down ↓ 210 lines elided ↑ open up ↑
1386 1372                  (void) snprintf(rtn, MAXLINESIZE, gettext("<unknown %d>"), grp);
1387 1373                  return (rtn);
1388 1374          }
1389 1375  }
1390 1376  
1391 1377  static void
1392 1378  print_hdr(char *prefix, ike_p1_hdr_t *hdrp)
1393 1379  {
1394 1380          (void) printf(
1395 1381              gettext("%s Cookies: Initiator 0x%llx  Responder 0x%llx\n"),
1396      -            prefix, ike_ntohll(hdrp->p1hdr_cookies.cky_i),
1397      -            ike_ntohll(hdrp->p1hdr_cookies.cky_r));
     1382 +            prefix, ntohll(hdrp->p1hdr_cookies.cky_i),
     1383 +            ntohll(hdrp->p1hdr_cookies.cky_r));
1398 1384          (void) printf(gettext("%s The local host is the %s.\n"), prefix,
1399 1385              hdrp->p1hdr_isinit ? gettext("initiator") : gettext("responder"));
1400 1386          (void) printf(gettext("%s ISAKMP version %d.%d; %s exchange\n"), prefix,
1401 1387              hdrp->p1hdr_major, hdrp->p1hdr_minor, xchgstr(hdrp->p1hdr_xchg));
1402 1388          (void) printf(gettext("%s Current state is %s"), prefix,
1403 1389              statestr(hdrp->p1hdr_state));
1404 1390          (void) printf("\n");
1405 1391  }
1406 1392  
1407 1393  static void
↓ open down ↓ 1640 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX