DNET_ADDR(3)

πŸ“¦ version 2.65build2, in ubuntu jammy

πŸ’– DNET_ADDR(3) πŸ’–

okay bestie, so this is a page from the Library Functions Manual β€” section 3, the "functions" section, the one where all the cool callable stuff lives. and today's main character is dnet_addr. she's giving DECnet glow-up energy and honestly? we're obsessed. ✨


🌸 NAME 🌸

dnet_addr β€” DECnet nodename to address translation

like... you give her a name, she gives you back the address. it's the matchmaker of the DECnet world fr fr. πŸ’Œ


πŸŽ€ SYNOPSIS πŸŽ€

#include <netdnet/dn.h>
#include <netdnet/dnetdb.h>

struct dn_naddr *dnet_addr (char *nodename)

two headers, one function, zero drama. you include both, you call her with a nodename, she hands you a pointer to a struct dn_naddr. that's the whole vibe. πŸ¦‹


✨ DESCRIPTION ✨

so here's the tea, bestie: dnet_addr goes and searches the decnet hosts file for nodename, and when she finds it she returns the DECnet address inside the dn_naddr structure. πŸ’…

and if there's no entry found? she returns NULL. no notes, no explanation, just NULL. it's giving ghosted, but like, documented ghosting. 😭

heads up: always check for that NULL before you go using the result, okay? she will not warn you twice. 🫢

πŸ”₯ EXAMPLE πŸ”₯

here's a whole little program showing her off. look at the main character energy:

#include <netdnet/dn.h>
#include <netdnet/dnetdb.h>
#include <sys/socket.h>

main(void)
{
    struct dn_naddr          *binaddr;
    struct sockaddr_dn       sockaddr;
    int                 sockfd;

    if ( (binaddr=dnet_addr("mv3100")) == NULL)
    {
        printf("No entry in /etc/decnet.conf for mv3100\n");
        exit(0);
     }
     if ((sockfd=socket(AF_DECnet,SOCK_SEQPACKET,DNPROTO_NSP)) == -1)
     {
              perror("socket");
              exit(-1);
     }

     sockaddr.sdn_family      = AF_DECnet;
     sockaddr.sdn_flags       = 0x00;
     sockaddr.sdn_objnum = 0x19;             /* MIRROR */
     sockaddr.sdn_objnamel    = 0x00;
     memcpy(sockaddr.sdn_add.a_addr, binaddr->a_addr,binaddr->a_len);

     if (connect(sockfd, (struct sockaddr *)&sockaddr,
          sizeof(sockaddr)) < 0)
     {
          perror("connect");
          exit(-1);
     }
     close(sockfd);
}

the way this does the whole thing β€” look up "mv3100", bail out politely with No entry in /etc/decnet.conf for mv3100 if it's not there, then open a socket with socket(AF_DECnet,SOCK_SEQPACKET,DNPROTO_NSP), build a struct sockaddr_dn with sdn_family = AF_DECnet, sdn_flags = 0x00, sdn_objnum = 0x19 (that's MIRROR, bestie, she told us in a comment πŸ’–), sdn_objnamel = 0x00, then memcpy the address bytes over from binaddr->a_addr for binaddr->a_len bytes, connect it up, and close(sockfd). iconic. no notes. periodt. πŸ‘‘


🌈 SEE ALSO 🌈

the whole friend group, go say hi:


and that's the whole page, bestie!! this one came from the DECnet database functions corner of the manual, dated July 28, 1998 β€” yes she's vintage, yes she still ate, we love a legacy queen πŸ’œπŸ‘‘

πŸ“¦ where this page comes from