-int
-exchange_nids (int cfd, ptl_nid_t my_nid, ptl_nid_t *peer_nid)
-{
- int rc;
- ptl_hdr_t hdr;
- ptl_magicversion_t *hmv = (ptl_magicversion_t *)&hdr.dest_nid;
-
- LASSERT (sizeof (*hmv) == sizeof (hdr.dest_nid));
-
- memset (&hdr, 0, sizeof (hdr));
-
- hmv->magic = __cpu_to_le32 (PORTALS_PROTO_MAGIC);
- hmv->version_major = __cpu_to_le16 (PORTALS_PROTO_VERSION_MAJOR);
- hmv->version_minor = __cpu_to_le16 (PORTALS_PROTO_VERSION_MINOR);
-
- hdr.src_nid = __cpu_to_le64 (my_nid);
- hdr.type = __cpu_to_le32 (PTL_MSG_HELLO);
-
- /* Assume there's sufficient socket buffering for a portals HELLO header */
- rc = sock_write (cfd, &hdr, sizeof (hdr));
- if (rc != 0) {
- perror ("Can't send initial HELLO");
- return (-1);
- }
-
- /* First few bytes down the wire are the portals protocol magic and
- * version, no matter what protocol version we're running. */
-
- rc = sock_read (cfd, hmv, sizeof (*hmv));
- if (rc != 0) {
- perror ("Can't read from peer");
- return (-1);
- }
-
- if (hmv->magic != __cpu_to_le32 (PORTALS_PROTO_MAGIC)) {
- fprintf (stderr, "Bad magic %#08x (%#08x expected)\n",
- __le32_to_cpu (hmv->magic), PORTALS_PROTO_MAGIC);
- return (-1);
- }
-
- if (hmv->version_major != __cpu_to_le16 (PORTALS_PROTO_VERSION_MAJOR) ||
- hmv->version_minor != __cpu_to_le16 (PORTALS_PROTO_VERSION_MINOR)) {
- fprintf (stderr, "Incompatible protocol version %d.%d (%d.%d expected)\n",
- __le16_to_cpu (hmv->version_major),
- __le16_to_cpu (hmv->version_minor),
- PORTALS_PROTO_VERSION_MAJOR,
- PORTALS_PROTO_VERSION_MINOR);
- }
-
- /* version 0 sends magic/version as the dest_nid of a 'hello' header,
- * so read the rest of it in now... */
- LASSERT (PORTALS_PROTO_VERSION_MAJOR == 0);
- rc = sock_read (cfd, hmv + 1, sizeof (hdr) - sizeof (*hmv));
- if (rc != 0) {
- perror ("Can't read rest of HELLO hdr");
- return (-1);
- }
-
- /* ...and check we got what we expected */
- if (hdr.type != __cpu_to_le32 (PTL_MSG_HELLO) ||
- PTL_HDR_LENGTH (&hdr) != __cpu_to_le32 (0)) {
- fprintf (stderr, "Expecting a HELLO hdr with 0 payload,"
- " but got type %d with %d payload\n",
- __le32_to_cpu (hdr.type),
- __le32_to_cpu (PTL_HDR_LENGTH (&hdr)));
- return (-1);
- }
-
- *peer_nid = __le64_to_cpu (hdr.src_nid);
- return (0);
-}
-