#include stdio #include string #include descrip #include stdlib #include ssdef #include #include /* * Description: Sample program to demonstrate how to create a DECdns object. * * Parameters: * This program takes 3 arguments. They are: * argv[0] = name of this program * argv[1] = name of object in string (printable) format * argv[2] = name of class in string (printable) format * * Returns: * Returns status from sys$dnsw, dns$_create_object function. */ main (int argc, char *argv[]) { struct $dnsitmdef parseitem[3]; /* Item list for parsing */ unsigned char class[dns$k_simplenamemax]; /* Opaque class name */ unsigned char fullname_buf[dns$k_fullnamemax]; /* Opaque object name */ int status; /* General routine status */ struct $dnsb dnsb; /* Used for nameserver status information */ unsigned short fname_len; /* Length of object name */ unsigned short class_len; /* Length of class name */ /* * Make certain that you have number of arguments you expect. */ if (argc != 3) { printf("USAGE: create_obj \n"); exit(0); } /* * Convert the object string name into opaque format. */ /* First item contains the address of the object string name */ parseitem[0].dns$w_itm_code = dns$_fromstringname; parseitem[0].dns$w_itm_size = strlen(argv[1]); parseitem[0].dns$a_itm_address = argv[1]; /* Second item contains the address of the buffer to receive the * opaque fullname of the object. */ parseitem[1].dns$w_itm_code = dns$_tofullname; parseitem[1].dns$w_itm_size = dns$k_fullnamemax; parseitem[1].dns$a_itm_address = fullname_buf; parseitem[1].dns$a_itm_ret_length = &fname_len; /* Zero terminates the itemlist to indicate no more item blocks. */ *((int *)&parseitem[2]) = 0; /* Use system service to convert object name to opaque format */ status = sys$dnsw(0, dns$_parse_fullname_string, &parseitem, &dnsb, 0, 0); /* * Must check both the return status from the service, plus the * status from the nameserver in all cases. */ if (status == SS$_NORMAL) { status = dnsb.dns$l_dnsb_status; } /* If error, print message and terminate. */ if (status != SS$_NORMAL) { printf("Error converting name %s\n", argv[1]); exit(status); } /* * Convert the class string name into opaque format. */ /* First item is the address of the class name in string format. */ parseitem[0].dns$w_itm_code = dns$_fromstringname; parseitem[0].dns$w_itm_size = strlen(argv[2]); parseitem[0].dns$a_itm_address = argv[2]; /* Second item is the address of the buffer which will contain the * opaque version of the class name. Size of the actual class name * will be found in class_len. */ parseitem[1].dns$w_itm_code = dns$_tosimplename; parseitem[1].dns$w_itm_size = dns$k_simplenamemax; parseitem[1].dns$a_itm_address = class; parseitem[1].dns$a_itm_ret_length = &class_len; /* Zero terminates the itemlist to indicate no more item blocks. */ *((int *)&parseitem[2]) = 0; /* Use system service to convert class name to opaque format */ status = sys$dnsw(0, dns$_parse_simplename_string, &parseitem, &dnsb, 0, 0); /* * Must check both the return status from the service, plus the * status from the nameserver in all cases. */ if (status == SS$_NORMAL) { status = dnsb.dns$l_dnsb_status; } /* If an error occurred, print out the message and terminate */ if (status != SS$_NORMAL) { printf("Error converting name %s\n", argv[2]); exit(status); } printf("Creating object \"%s\", class \"%s\"\n", argv[1], argv[2]); /* Create the object */ status = create_object(class, class_len, fullname_buf, fname_len); /* If an error occurred, print it out and terminate */ if (status != SS$_NORMAL) { printf("Status from create_object = %d\n", status); } exit(status); } /* * Description: Function to create a DECdns object. * * Parameters: * class_name = address of the opaque simple name of the class * to assign to the object * class_len = length in bytes of the class opaque simple name * object_name = address of opaque full name of the object to create * in the namespace. * object_len = length (in bytes) of the opaque full name of the * object to create * * Returns: * Returns status from sys$dnsw, dns$_create_object function. * */ int create_object( unsigned char *class_name, unsigned short class_len, unsigned char *object_name, unsigned short object_len) { struct $dnsitmdef createitem[7]; /* Item list used by system service */ struct $dnscversdef version; /* Version assigned to the object */ struct $dnsb dnsb; /* Contains DECdns server status */ int status; /* Status returns from system service */ /* * Construct the item list that creates the object */ /* Item contains opaque simple class name of object to be created */ createitem[0].dns$w_itm_size = class_len; createitem[0].dns$w_itm_code = dns$_class; createitem[0].dns$a_itm_address = class_name; /* Item contains opaque full name of object to be created */ createitem[1].dns$w_itm_size = object_len; createitem[1].dns$w_itm_code = dns$_objectname; createitem[1].dns$a_itm_address = object_name; /* Item contains two byte version of object to be created */ version.dns$b_c_major = 2; version.dns$b_c_minor = 0; createitem[2].dns$w_itm_size = sizeof(struct $dnscversdef); createitem[2].dns$w_itm_code = dns$_version; createitem[2].dns$a_itm_address = &version; /* Zero terminates the itemlist to indicate no more item blocks. */ *((int *)&createitem[3]) = 0; status = sys$dnsw(0, dns$_create_object, &createitem, &dnsb, 0, 0); /* * Must check both the return status from the service, plus the * status from the nameserver in all cases. */ if (status == SS$_NORMAL) { status = dnsb.dns$l_dnsb_status; } return(status); }